package com.haisen.dataobject.mapper.base;

import com.haisen.core.utils.MyMapper;
import com.haisen.dataobject.dto.ItemDto;
import com.haisen.dataobject.entity.Item;
import com.haisen.dataobject.query.ItemQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ItemMapper extends MyMapper<Item> {

     @Select("select IFNULL(max(id),0) as 'id'  from tb_item")
     Long selectMaxId();


     @Select("select a.area_id as areaId,a.title,a.sell_point as sellPoint,a.price,a.num,a.barcode,a.image,a.cat_id as catId,b.name as catName,a.up " +
             "from tb_item a,tb_item_cat b where a.cat_id = b.id;")
     @Results({
             @Result(property="itemParamValueList",javaType=List.class,column="id",many=@Many(select="com.haisen.dataobject.mapper.base.ItemParamValueMapper.selectKeysByItemId"))
     })
     List<ItemDto> findAllDto();

     /**
      * list页面有查询功能，增加动态sql语句查询
      */
     @SelectProvider(type=com.haisen.dataobject.query.ItemDynaSqlProvider.class,method="selectWithItemSql")
     @Results({
             @Result(property="itemParamValueList",javaType=List.class,column="uid",many=@Many(select="com.haisen.dataobject.mapper.base.ItemParamValueMapper.selectKeysByItemId"))
     })
     List<ItemDto> findDtoByWhere(ItemQuery itemQuery);

     @SelectProvider(type=com.haisen.dataobject.query.ItemDynaSqlProvider.class,method="selectCountWithItemSql")
     long selectDtoCountByWhere(ItemQuery itemQuery);

}